//
//  HRExampleSoundCollectionViewCell.m
//  Hear
//
//  Created by mac on 2017/10/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRExampleSoundCollectionViewCell.h"
#import "HRDynamicCell.h"
@interface HRExampleSoundCollectionViewCell ()
@property(nonatomic, strong)UIImageView *backImageView;
@property(nonatomic, strong)UIView *iconView;
@property(nonatomic, strong)UIImageView *iconImageView;
@property(nonatomic, strong)UILabel *contentLabel;
@property(nonatomic, strong)UIImageView *sexImageView;
@property(nonatomic, strong)HRSoundButton *soundButton;

@end
@implementation HRExampleSoundCollectionViewCell

-(void)setModel:(HRSoundExampleModel *)model{
    [self.iconImageView setImageURL:[NSURL URLWithString:model.HeadImageUrl]];
    
    self.contentLabel.text = [NSString stringWithFormat:@"%@、%@",model.NickName,model.UserGroup];
    
    if ([model.Sex intValue] ==1){
        self.sexImageView.image = [UIImage imageNamed:@"nim_male"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"nim_female"];
    }
    
    self.soundButton.exampleModel = model;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    
    CGFloat leftPading = 10;
    CGFloat cellW = kFullWidth/2;
    
    CGFloat topPading = 20;
    
    
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(leftPading, 0, cellW-leftPading, cellW)];
    [self addSubview:self.backView];

    UIImageView *backImageView = [UIImageView new];
    backImageView.image = [UIImage imageNamed:@"声音名片背景"];
    [self.backView addSubview:(self.backImageView=backImageView)];
    backImageView.frame = CGRectMake(0, topPading, cellW-leftPading, cellW-topPading*2);
    backImageView.userInteractionEnabled = YES;
    
    self.iconView = [UIView new];
    self.iconView.backgroundColor = [UIColor whiteColor];
    [self.backView addSubview:self.iconView];
    self.iconView.frame = CGRectMake((self.backView.width-50)/2, 0, 50, 50);
    self.iconView.layer.cornerRadius = self.iconView.width/2;
    self.iconView.clipsToBounds = YES;
    self.iconView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.iconView.layer.shadowRadius      = 3;
    self.iconView.layer.shadowOpacity     = 0.2;
    self.iconView.layer.shadowOffset      = CGSizeMake(1, 1);
    self.iconView.layer.shadowPath        = [UIBezierPath bezierPathWithRect:self.iconView.bounds].CGPath;
    
    self.iconImageView = [UIImageView new];
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.iconView addSubview:self.iconImageView];
    self.iconImageView.frame = CGRectMake(5, 5, 40, 40);
    self.iconImageView.layer.cornerRadius = self.iconImageView.width/2;
    self.iconImageView.clipsToBounds = YES;
    self.iconImageView.userInteractionEnabled = NO;
    
    UIImageView *sexImageView = [UIImageView new];
    [self.backView addSubview:(self.sexImageView=sexImageView)];
    sexImageView.frame = CGRectMake(self.iconView.right, self.iconView.bottom-18, 15, 15);
    
    
    
    self.contentLabel = [UILabel new];
    self.contentLabel.font = CustomUIFont(13);
    self.contentLabel.textColor =FirstTextColor;
    [self.backImageView  addSubview:self.contentLabel];
    self.contentLabel.frame = CGRectMake(leftPading, topPading*2, self.backImageView.width-leftPading*2, 40);
    self.contentLabel.numberOfLines = 2;
    self.contentLabel.textAlignment = 1;
    
    WeakSelf
    self.soundButton = [[HRSoundButton alloc] initWithFrame:CGRectMake(leftPading*2, self.backImageView.bottom-30, self.backImageView.width-leftPading*4, 50)];
    [self.backView addSubview:self.soundButton];
    self.soundButton.playExampleMedioBlock = ^(HRSoundExampleModel *currentExampleModel) {
        if (weakSelf.playExampleMedioBlock){
            weakSelf.playExampleMedioBlock(currentExampleModel);
        }
    };
}

@end
